
<!DOCTYPE html>
<html class="rem bg">
<head>
    <meta charset="utf-8"/>
    <meta name="keywords" content=""/>
    <meta name="description" content=""/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
    <meta content="yes" name="apple-mobile-web-app-capable" />
    <meta content="black" name="apple-mobile-web-app-status-bar-style" />
    <meta content="telephone=no" name="format-detection" />
    <title>附近网咖</title>
    <link rel="stylesheet" href="{{url('css/reset.m.css')}}"/>
    <link rel="stylesheet" href="{{url('css/wx.css')}}"/>
    {{--<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=3TqQQVGGSntGErSR8GifaIEG"></script>--}}
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=sMaz1fl9W61ZQUeD8ZMPwvRKfXduAwSa"></script>
</head>
<body>
<article class="page">
    <!--    <header class="header">-->
    <!--        <h4>附近网鱼</h4>-->
    <!--    </header>-->
    <main class="main">
        <div class="store-list">
            <input type="search" placeholder="请输入想查找的门店" class="input input-db" id="search" name="search">
            <div class="load tac"><img src="{{url('img/wx_loading.gif')}}" alt=""></div>
            <dl class="store-list-blk">

            </dl>
        </div>
    </main>
    <footer class="footer">

    </footer>
    <div id="map" style="display: none;"></div>
</article>
<script src="{{url('js/zepto.min.js')}}"></script>
<script src="{{url('js/fastclick.js')}}"></script>
<script>
    if (typeof FastClick === 'function') {
        FastClick.attach(document.body);
    }

    var keyword = '',
            load = $('.load');

    var map = new BMap.Map("map");
    var geolocation = new BMap.Geolocation();
    geolocation.getCurrentPosition(function (r) {
        if (this.getStatus() == BMAP_STATUS_SUCCESS) {
            lng = r.point.lng;
            lat = r.point.lat;
            localPoint = lng + ',' + lat;
            queryShops(localPoint);
        } else {
            alert('定位失败');
        }
    }, {enableHighAccuracy: true});

    var pois;

    $('#search').on('keyup', function(event){
        if(event.keyCode==13) {
            keyword = $(this).val();
            queryShops('');
        }
    });
    function queryShops(localPoint) {
        load.show();
        var url = "http://api.map.baidu.com/geosearch/v3/nearby?callback=?";
        $.getJSON(url, {
                    'q' : keyword,
                    'ak': 'sMaz1fl9W61ZQUeD8ZMPwvRKfXduAwSa',
                    'geotable_id': 185675,
                    'location': localPoint,
                    'radius': 50000,
                    'sortby': 'distance:1',
                    'page_size': 50
                }, function (res) {

             console.log(res);
                    load.hide();
                    if(res.total) {
                        pois = res.contents;
                        var html = '';
                        $.each(res.contents, function (i, item) {
                            if (item.tel == 'undefined' || !item.tel) {
                                item.tel = '无';
                            }
                            html += '<dd class="clr">';
                            html += '<a href="javascript:setSelectPoi('+i+')" class="clr">';
                            html += '<div class="info">';
                            html += '<span class="f-lt flr" id="dest-point" data-local="' + item.location + '">距离：' + (item.distance / 1000).toFixed(2) + 'km</span>';
                            html += '<h5>' + item.title + ' <i class="i-icon walk">&#xe60b;</i><i class="i-icon transit">&#xe609;</i></h5>';
                            //                    html += '<p class="f-lt">电话：' + item.tel + '</p>';
                            html += '<p class="f-lt">地址：' + item.address + '</p>';
                            html += '</div>';
                            html += '</a>';
                            html += '</dd>';
                        });
                    }else {
                        html = '<dd class="tac"><h2>对不起，没有找到符合的门店</h2></dd>'
                    }

                    $('.store-list-blk').html(html);
                }
        );
    }

    function setSelectPoi (i) {
        sessionStorage.setItem('point',localPoint);
        sessionStorage.setItem('lng',lng);
        sessionStorage.setItem('lat',lat);
        sessionStorage.setItem('poi',JSON.stringify(pois[i]));
        location.href = '{{url('wx/barInfo')}}';
    }

    function writeObj(obj){
        var description = "";
        for(var i in obj){
            var property=obj[i];
            description+=i+" = "+property+"\n";
        }
        alert(description);
    }
</script>
</body>
</html>